<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item label="审核管理">
          <el-input v-model="filters.username" placeholder="请输入名称"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-select v-model="filters.state" placeholder="请选择">
            <el-option
                v-for="item in empss"
                :key="item.id"
                :label="item.value"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getEmployee">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <!--		:data :绑定的数据-->
    <!--		v-loading: 页面css样式等东西加载之后加载加载数据-->
    <!--		prop:对应的是:data绑定的对象的属性-->
    <!--		label :描述-->

    <el-table :data="emp" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" label="序号" width="100">
      </el-table-column>
      <el-table-column prop="id" label="主键ID" width="100">
      </el-table-column>
      <el-table-column prop="name" label="店名" width="130" sortable>
      </el-table-column>
      <el-table-column prop="tel" label="电话" width="200" sortable>
      </el-table-column>
      <el-table-column prop="state" label="审核状态" width="140" :formatter="formatSex" sortable>
      </el-table-column>
      <el-table-column prop="registerTime" label="注册时间" width="140"  sortable>
      </el-table-column>
      <el-table-column prop="address" label="地址" width="150" sortable>
      </el-table-column>
      <el-table-column  prop="logo" label="logo" width="260" sortable>
        <template slot-scope="scope">
          <!-- scope.row获取当前行所有数据 作用域插槽获取当前行的数据（可以是图片连接如下：:src="scope.row.iconImgLarge"） -->
          <el-image style="width: 80px; height: 80px" :src="scope.row.logo" fit=""></el-image>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="warning" size="small" @click="handleEdit(scope.row)"  >详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页条-->
    <el-col :span="24" class="toolbar">
      <el-button type="danger" @click="batchRemove"  :disabled="this.sels.length===0" >批量驳回</el-button>
      <!--			current-change:自带的事件,我当前页发生改变时,就会触发此事件-->
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="5" :total="total" style="float:right;">
      </el-pagination>
    </el-col>

    <!--展示界面-->
    <el-dialog title="查看" :visible.sync="addFormVisible"  :close-on-click-modal="false" style="background-color: skyblue"  >
      <el-form :model="addForm" label-width="80px" :rules="addFormRules" ref="addForm"  >
        <el-form-item label="店名" prop="name">
          <el-input v-model="addForm.name" auto-complete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="tel">
          <el-input v-model="addForm.tel" auto-complete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="审核状态" :formatter="formatSex" prop="state">
          <el-input disabled v-model="addForm.state== 1 ? '等待审核' : addForm.state == 2 ? '审核通过，待激活' : addForm.state == 3 ? '激活成功' : '驳回'" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="注册时间" prop="registerTime">
          <el-input v-model="addForm.registerTime" auto-complete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="addForm.address" auto-complete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="logo" prop="logo">
          <el-image style="width: 80px; height: 80px" :src="addForm.logo" fit=""></el-image>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addFormVisible = false">取消</el-button>
        <el-button type="success" @click.native="addSubmit" :loading="addLoading" v-if="[1].includes(addForm.state)">通过</el-button>
        <el-button type="success" @click.native="addSubmit" :loading="addLoading" v-if="[2].includes(addForm.state)" disabled>审核通过，待激活</el-button>
        <el-button type="success" @click.native="addSubmit" :loading="addLoading" v-if="[3].includes(addForm.state)" disabled>激活成功</el-button>
        <el-button type="success" @click.native="addSubmit" :loading="addLoading" v-if="[4].includes(addForm.state)" disabled>已驳回</el-button>
        <el-button type="danger" @click.native="bh" :loading="addLoading"  v-if="[1].includes(addForm.state)">驳回</el-button>
      </div>
    </el-dialog>
    <!--驳回界面-->
    <el-dialog title="驳回说明" :visible.sync="addbhFormVisible"  :close-on-click-modal="false" style="background-color: skyblue"  >
      <el-form :model="addbhFormVisible" label-width="80px"  >
        <el-form-item label="原因" prop="cause">
          <el-input v-model="cause"  placeholder="请输入驳回原因" auto-complete="off" ></el-input>
          <el-button @click.native="addbhFormVisible = false">取消</el-button>
          <el-button type="success" @click.native="handleDel" :loading="addLoading" >提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </section>
</template>

<script>

export default {
  data() {
    return {
      filters: {
        username: '',
        state:''

      },
      empss:[
        {
          id:1,
          value:'待审核'
        },{
          id:2,
          value:'审核通过，待激活'
        },{
          id:3,
          value:'激活成功'
        },{
          id:4,
          value:'驳回'
        }
      ],
  cause:'',
      //审核下拉框数据
      emp: [],
      total: 0,
      page: 1,
      listLoading: false,
      sels: [],//列表选中列
      addFormVisible: false,//新增界面是否显示
      addbhFormVisible:false,//驳回表单是否显示
      addLoading: false,
      disable:'',
      addFormRules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ]
      },
      //新增界面数据
      addForm: {
        name: '',
        tel: '',
        registerTime:'',
        address:'',
        logo:'',
        admin:{
          username:'',
          phone:'',
          email:''
        }
      }
    }
  },
  methods: {
    //性别显示转换
    //row 当前行row = user  column当前列
    formatSex: function (row) {
      switch (row.state) {
        case 1 :
          return "待审核"
        case 2:
          return "审核通过，待激活"
        case 3:
          return "激活成功"
        case 4:
          return "驳回"
      }
    },

    handleCurrentChange(val) {
      //var 就是当前页的数据
      this.page = val;
      this.getEmployee();
    },
    //获取审核列表
    getEmployee() {
      //封装的数据
      let para = {
        //page 就是当前页
        page: this.page,
        //这个是高级查询的条件
        keyword: this.filters.username,
        state:this.filters.state
      };
      console.log(this.parentId)
      this.listLoading = true;

      //NProgress.start();
      this.$http.post("/shop/findPage ",para).then((res) => {
        // console.log("后端发送过来的分页数据:"+JSON.stringify(res));
        //
        console.log(res)
        this.total = res.data.total;
        //
        this.emp = res.data.list;
        //关闭进度条
        this.listLoading = false;
        //NProgress.done();
      });
    },
    //获取上级审核列表
    findemps() {
      //封装的数据
      this.listLoading = true;
      //NProgress.start();
      this.$http.get("/shop").then((res) => {
        console.log(res)
        this.emps = res.data.data
        //关闭进度条
        this.listLoading = false;
        //NProgress.done();
      });
    },
    //获取审核管理员
    findManagers() {
      //封装的数据
      this.listLoading = true;
      //NProgress.start();
      this.$http.get("/shop/findManagers").then((res) => {
        console.log(res)
        this.Managers = res.data.data
        //关闭进度条
        this.listLoading = false;
        //NProgress.done();
      });
    },
    //新增表单 获取所有的审核人员
    findManager() {
      //封装的数据
      this.listLoading = true;
      this.$http.get("/shop").then((res) => {
        console.log(res)
        this.empList = res.data.data
        //关闭进度条
        this.listLoading = false;
        //NProgress.done();
      });
    },
    //驳回
    bh:function (){
      this.addbhFormVisible = true
    },
    // 驳回提交确认
    handleDel: function () {
         this.$confirm('此操作将驳回该用户的申请, 是否继续?', '提示', {
           confirmButtonText: '确定',
           cancelButtonText: '取消',
           type: 'warning'
         }).then(() => {
           this.listLoading = true;
           let para = {
             cause: this.cause,
             id: this.addForm.id
           }
           //NProgress.start();
           this.$http.post("/shop/reject", para).then((res) => {
             this.listLoading = false;
             //NProgress.done();
             this.$message({
               message:res.data.message,
               type: res.data.success,
             });
             this.getEmployee();
           });
         })
    },
    //显示编辑界面
    handleEdit: function (row) {
      // alert(row)
      //显示编辑页面的模态框
      this.addFormVisible = true;
      //Object.assign 是拷贝对象 BeanUtil.copyof()
      //拷贝对象
      this.addForm = Object.assign({},row)
    },
    //通过
    addSubmit: function () {
      //$refs调用js 原生dom元素
      //validate
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认通过吗？', '提示', {}).then(() => {
            //这里才是我们处理数据的地方
            this.addLoading = true;
            //Object.assign 复制对象的
            // 处理状态
            let para = Object.assign({}, this.addForm);
            console.log(para)
            this.$http.post("/shop",para).then((res) => {
              this.addLoading = false;
              //elementUi的提示弹框
              this.$message({
                message: res.data.message,
                type: res.data.success?"success":"error"
              });
              //重新set数据
              this.$refs['addForm'].resetFields();
              this.addFormVisible = false;
              this.getEmployee();
            });
          });
        }
      });
    },
    //复选勾选框的方法
    selsChange: function (sels) {
      this.sels = sels;
    },
    //批量驳回
    batchRemove: function () {
      var ids = this.sels.map(item => item.id);
      this.$confirm('确认驳回选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        let para = { ids: ids };
        this.$http.post("emp/batchRemove",para).then((res) => {
          this.listLoading = false;
          //NProgress.done();
          this.$message({
            message: '驳回成功',
            type: 'success'
          });
          this.getEmployee();
        });
      }).catch(() => {

      });
    }
  },
  //就是页面已加载完成就会去触发这个mounted
  mounted() {
    //展示全部数据
    this.getEmployee();
    //下拉框数据展示上级审核
    this.findemps();
    //获取审核管理员下拉框
    this.findManager();
    this.findManagers();
    //审核联级  获取
    this.getTree();
  }
}

</script>

<style scoped>

</style>